/*
 * @# HomeAction.java 2011-11-4 上午09:28:02
 * 
 * Copyright (C) 2010 - 2011 广州羿安信息科技有限公司
 * Guangzhou ianswer information technology co. ltd.
 * 
 * All rights reserved!
 */
package com.ianswer.experiments.templates;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.ianswer.common.struts.BaseAction;

/**
 * @author alvin hwang
 */
@Namespace("/")
public class HomeAction extends BaseAction {

	private static final long serialVersionUID = 3311591722183161292L;

	private String user;
	private String template;
	
	private List<Stuff> stuffs;
	
	@Action(value = "home", results = {@Result(name = SUCCESS, location="/${template}")})
	public String home() throws IOException {
		template = Templates.getTemplate(user);
		
		stuffs = new ArrayList<Stuff>();
		stuffs.add(new Stuff("我是谁", "我是一只小小鸟, 想来飞却飞不高", 12L));
		stuffs.add(new Stuff("I am Robot", "我是阿西莫夫笔下的一个角色", 90L));
		
		return SUCCESS;
	}

	@Action(value = "stuffs")
	public String stuffs() throws IOException {
		writeJson(new Stuff("我是谁", "好吧, 我承认, 我是异步过来的", 0L));
		return NONE;
	}
	
	public void setUser(String user) {
		this.user = user;
	}

	public String getTemplate() {
		return template;
	}

	public List<Stuff> getStuffs() {
		return stuffs;
	}
	
}
